package com.easytouch.vm;

import android.app.Application;
import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;

import com.easytouch.core.Configure;
import com.easytouch.core.utils.CrashHandler;
import com.easytouch.core.utils.Log;
import com.easytouch.core.utils.SDCardTools;

/**
 * Created by gulin on 2017/7/20.
 */

public class AppApplication extends Application {
    public static Context context;
    public static String versionName;
    public static String path;
    public static String ext_path;

    @Override
    public void onCreate() {
        super.onCreate();
        context = getApplicationContext();
        versionName = getVersionName();
        path = SDCardTools.getSDCardPath() + "/Android/data/" + getPackageName();
        ext_path = "/mnt/extsd/"+ this.getPackageName();

        /**
         * 开始初始化驱动
         */
        //初始化crashhandler
        CrashHandler crashHandler = CrashHandler.getInstance();
        crashHandler.init();
        //初始化Log
        Log.maintainDays = 5;
        Log.isInfoEnable = true;
        Log.isDebugEnable = true;
        Log.isErrorEnable = true;
        //初始化Configure
        Configure.context = context;
        Configure.path = path;
        Configure.version = versionName;
    }

    public String getVersionName() {
        PackageManager pm = this.getPackageManager();
        try {
            PackageInfo pi = pm.getPackageInfo(this.getPackageName(), 0);
            return pi.versionName;
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
            return null;
        }
    }
}
